/**
 * 
 */
package com.witframework.baseapp.security.system;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;

import com.witframework.core.WitFrameWork;
import com.witframework.core.log.AuditLogger;

/**
 * @author wuxinyang
 * Jul 8, 2009 5:45:11 PM
 * 
 */
public class DefaultLogger implements AuditLogger {

	/* (non-Javadoc)
	 * @see com.witframework.core.log.AuditLogger#info(java.lang.String, java.util.Date, int, java.lang.String, int, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
	 */
	public void info(String user_id, Date date_time, String return_code, String error_description, Date duration, String client_ip, String operation,
			String object_id, String transaction_data) {
		SystemLog log=new SystemLog(user_id, date_time, return_code, error_description, duration, client_ip, operation,
				object_id, transaction_data);
		WitFrameWork.getSimpleBaseService(SystemLog.class).save(log);

	}

	/* (non-Javadoc)
	 * @see com.witframework.core.log.AuditLogger#info(javax.servlet.http.HttpServletRequest, int, java.lang.String, int, java.lang.String, java.lang.String, java.lang.String)
	 */
	public void info(HttpServletRequest request, String return_code, String error_description, Date duration, String operation, String object_id,
			String transaction_data) {
		String remoteAddr = request.getRemoteAddr();
		String user="";
		if(request.getUserPrincipal()!=null)
			user=request.getUserPrincipal().getName();
		else if(request.getRemoteUser()!=null)
			user=request.getRemoteUser();
		else
			user="anonymous";
		info(user,new Date(),return_code,error_description,duration,remoteAddr,operation,object_id,transaction_data);

	}

}
